let integrationName = ''; let integration = { sender: '', lang: '', type: '', errorMessage:'', data: { playerTokenId: '', clientToken: '', currencyCode: '', balance: 0, winAmount: 0, totalBet: 0, activeBet: 0 } }; let integrationIframe = ''; let gameEvent = null; //disable quit when no returnurl function getParameterByName(name) { name = name.toLowerCase().replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)") var results = null; try { results = regex.exec(location.search.toLowerCase()); } catch (e) { } return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } function getParentParameterByName(name) { name = name.toLowerCase().replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); var results = null; try { results = regex.exec(parent.location.search.toLowerCase()); } catch (e) { } return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } function getReturnurl() { if (getParameterByName('returnUrl') !== '') { return getParameterByName('returnUrl'); } else if (getParentParameterByName('returnUrl') !== '') { return getParentParameterByName('returnUrl'); } else { return false } } //disable quit when no returnurl END window.addEventListener("message", function (event) { if (gameEvent === null) { return; } let message = event.data; if(message.name === 'integration') { integration.sender = message.sender || ''; integration.lang = message.lang || ''; integration.type = message.type || ''; integration.errorMessage = message.errorObject || ''; if(message.data) { let data = message.data; integration.data.playerTokenId = data.playerTokenId || ''; integration.data.clientToken = data.clientToken || ''; integration.data.currencyCode = data.currencyCode || ''; integration.data.balance = data.balance || 0; integration.data.winAmount = data.winAmount || 0; integration.data.totalBet = data.totalBet || 0; integration.data.activeBet = data.activeBet || 0; } gameEvent[integration.type](); } }); function GameEvents() { this.onAppFrameReady = function() { }; this.quit = function() { }; this.gameReady = function() { }; this.gameLoadFailed = function() { }; this.cashier = function() { }; this.gameDataLoaded = function() { }; this.roundStart = function() { }; this.roundStarted = function() { }; this.autoPlayStarted = function() { }; this.autoPlayStoped = function() { }; this.balance = function() { }; this.ticketReceived = function() { }; this.roundEnded = function() { }; this.fatalError = function() { }; this.uiEnable = function() { }; this.uiDisable = function() { }; this.hideLoader = function() { }; this.showLoader = function() { }; this.updateBet = function () { } this.betAction = function() { }; this.sendMessage = function() { }; this.receiveMessage = function() { }; this.errorMessage = function() { }; } function PariPlayGameEvents() { this.onAppFrameReady = function() { this.sendMessage('onAppFrameReady'); }; this.quit = function() { this.sendMessage('quit'); }; this.gameReady = function() { this.sendMessage('gameReady'); }; this.cashier = function() { let data = { "reason": "Ribbon", "target": "" }; this.sendMessage('cashier', data); }; this.gameDataLoaded = function() { let data = { "LoadGameData": { "PlayerTokenId": integration.data.playerTokenId, "GameName": integration.sender, "HomeUrl": "", "ClientToken": integration.data.clientToken, "CurrencyCode": integration.data.currencyCode, "SessionData": { "TotalBet": 0, "TotalWin": 0, "SessionBalance": integration.data.balance }, } }; this.sendMessage('gameDataLoaded', data); }; this.roundStart = function() { let data = { "totalBet": integration.data.totalBet }; this.sendMessage('roundStart', data); }; this.roundStarted = function() { let data = { "balanceBefore": integration.data.balance }; this.sendMessage('roundStarted', data); }; this.balance = function() { let data = { "amount": integration.data.balance }; this.sendMessage('balance', data); }; this.ticketReceived = function() { let data = { "Input": { "Stake": 0 }, "Ticket": { "ChangeBetAllowed": true, "IsWin": true, "PaytableId": 0, "WinMultiplier": 0, "TotalBet": 0, "TotalWinAmount": 0, "Id": 0, "IsFreeRound": false }, "Balance": { "BalanceBefore": 0, "BalanceAfter": 0, "TotalWinAmount": 0, "TotalBetAmount": 0, "TotalFreeSpinsWinAmount": 0, "Id": 0 }, "Status": { "ErrCode": 0, "ErrType": 0, "UniqueErrorCode": 0 } }; this.sendMessage('ticketReceived', data); }; this.roundEnded = function() { let data = { "winAmount": integration.data.winAmount }; this.sendMessage('roundEnded', data); }; this.sendMessage = function(type, data = null) { let messageObject = { sender: integration.sender, lang: integration.lang, type: type, }; if (data !== null && data !== undefined) { messageObject.data = data; } console.log("PARIPLAY INTEGRATION MESSAGE: ", messageObject); window.parent.postMessage(messageObject, '*'); }; this.receiveMessage = function() { window.addEventListener('message', EventHandler, false); function EventHandler(eventData) { let sendMessage = false; switch (eventData.data.type) { case "stopAutobet": sendMessage = true; eventData.data.type = "integrationStopAutobet"; break; case "disableSpin": sendMessage = true; eventData.data.type = "integrationDisableSpin"; break; case "enableSpin": sendMessage = true; eventData.data.type = "integrationEnableSpin"; break; } if(sendMessage) integrationIframe.contentWindow.postMessage(eventData.data, "*"); } }; } function GanGameEvents() { this.loaded = false; this.dataLoaded = false; this.balanceUpdated = false; this.lastEvent = ''; this.lastSendEvent = ''; this.onAppFrameReady = function() { ganEventDispatch("gameLoaded"); }; this.quit = function() { ganEventDispatch("gameClosing"); }; this.gameReady = function() { //ganEventDispatch("gameLoaded"); this.loaded = true; if(this.dataLoaded) { this.gameDataLoaded(); } }; this.gameDataLoaded = function() { this.dataLoaded = true; if(!this.loaded) { return false; } if(this.lastSendEvent !== 'playStopped') { ganEventDispatch("playStopped"); this.lastSendEvent = 'playStopped'; } }; this.gameLoadFailed = function() { ganEventDispatch("gameLoadFailed"); }; this.betAction = function() { if(integration.data.activeBet === 0) { this.roundEnded(); } else { this.roundStarted(); } }; this.roundStarted = function() { if(!this.balanceUpdated) { this.lastEvent = 'roundStarted'; return false; } if(integration.data.activeBet > 0) { if(this.lastSendEvent !== 'playStarted') { ganEventDispatch("playStarted"); this.lastSendEvent = 'playStarted'; } } }; this.roundEnded = function() { if(!this.balanceUpdated) { this.lastEvent = 'roundEnded'; return false; } if(this.lastSendEvent !== 'playStopped') { ganEventDispatch("playStopped"); this.lastSendEvent = 'playStopped'; } }; this.fatalError = function() { ganEventDispatch("fatalError"); }; this.uiEnable = function() { ganEventDispatch("uiEnable"); }; this.uiDisable = function() { ganEventDispatch("uiDisable"); }; this.hideLoader = function() { ganEventDispatch("hideLoader"); }; this.showLoader = function() { ganEventDispatch("showLoader"); }; this.receiveMessage = function(type, data = {}) { if(!this.balanceUpdated && type === 'integrationRefreshBalance') { this.balanceUpdated = true; if(this.lastEvent === 'roundStarted') { this.roundStarted(); } else if(this.lastEvent === 'roundEnded') { this.roundEnded(); } } let eventData = { data: { type: type } }; integrationIframe.contentWindow.postMessage(eventData.data, "*"); }; } function SolidGameEvents() { this.roundStarted = function() { this.sendMessage('gameBusy'); }; this.roundEnded = function() { this.sendMessage('gameNotBusy'); }; this.quit = function() { if(bowser.mobile) this.sendMessage('exit'); }; this.sendMessage = function(type) { let message = {"event": type}; console.log("SOLID INTEGRATION MESSAGE:", message); window.parent.postMessage(JSON.stringify(message), '*'); }; this.receiveMessage = function() { window.addEventListener('message', EventHandler, false); function EventHandler(event) { let data = event.data; let sendMessage = false; if (typeof data == 'string') { data = JSON.parse(data); } switch (data.event) { case "playInterrupted": sendMessage = true; data.type = "integrationStopAutobet" integrationIframe.contentWindow.postMessage(data, "*"); data.type = "integrationDisableSpin"; break; case "playResumed": sendMessage = true; data.type = "integrationEnableSpin"; break; } if(sendMessage) integrationIframe.contentWindow.postMessage(data, "*"); } }; } function MicrogamingGameEvents() { this.quit = function() { this.sendMessage('close_application'); }; this.gameReady = function() { this.sendMessage('bridge_api_ready'); }; this.cashier = function() { this.sendMessage('launch_banking'); }; this.roundStarted = function() { this.sendMessage('busy'); }; this.balance = function() { this.sendMessage('player_activity'); }; this.roundEnded = function() { this.sendMessage('idle'); }; this.sendMessage = function (type, data = null) { let id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); let messageObject = { "Id": id, "Name" : type, "Body" : null, "Type" : "REQUEST", "Origin" : "embeddedgame", "SenderId" : "EMBEDDED_GAME", }; if (type == "busy" || type == "idle" || type == "close_application") { messageObject.Type = "NOTIFICATION"; } console.log('MICROGAMING INTEGRATION MESSAGE: ', messageObject); window.parent.postMessage(messageObject, '*'); }; this.receiveMessage = function() { window.addEventListener('message', EventHandler, false); function EventHandler(event) { let data = event.data; let sendMessage = false; if (typeof (data) === 'string') { data = JSON.parse(data); } if(data.Name){ switch (data.Name.toLowerCase()) { case "pause_gameplay": sendMessage = true; data.type = "integrationStopAutobet" integrationIframe.contentWindow.postMessage(data, "*"); data.type = "integrationDisableSpin"; break; case "resume_gameplay": sendMessage = true; data.type = "integrationEnableSpin"; break; } } if(sendMessage) integrationIframe.contentWindow.postMessage(data, "*"); } }; } function ganEventReceive(data) { if(gameEvent === null) return false; console.log('GAN INTEGRATION MESSAGE', data); if(data) { if (data === 'gameProceed') { gameEvent.receiveMessage('integrationEnableSpin'); gameEvent.receiveMessage('integrationRefreshBalance'); } else if (data === 'gamePause') { gameEvent.balanceUpdated = false; gameEvent.receiveMessage('integrationDisableSpin'); } else if (data === 'refreshBalance') { gameEvent.receiveMessage('integrationRefreshBalance'); } else if (data === 'failedCommunication') { gameEvent.receiveMessage('integrationFailedCommunication'); } else if (data === 'connectionEstablished') { gameEvent.receiveMessage('integrationConnectionEstablished'); } else if (data === 'resizeGame') { gameEvent.receiveMessage('integrationResizeGame'); } } } function RelaxGameEvents() { this.gameDataLoaded = function() { FEIM.configure({ // The received response from /getclientconfig/, or an object adhering to its format // (Relax game server users only): // clientConfig: clientconfigResponse, // The casino login response, or an object adhering to its format // (Relax game server users only): // loginResponse: casinoLoginResponse, // When clientConfig and loginResponse cannot be provided // (only when not using the Relax game server): p2pConfig: {currency: integration.data.currencyCode}, /* If set to true, FEIM will handle the responsibilities of RgPostMessageAPI library. If true, RgPostMessageAPI library or any equivalent/duplicate integration must be removed from the game. */ // handleRgPostMessageAPI: true, /* Some jurisdictions require that the game needs to wait for a user confirmation when a bonus game is reached. Set this to false if the game handles it internally. */ // handleFeaturePause: true, // Optional, see showError: // showErrorMessageCallback: MY_GAME.showInGameErrorMessage, }); // console.log("configure", integration.data.currencyCode ); }; this.roundStarted = function() { FEIM.send.roundStarted({ // playResponse: receivedPlayResponse, // playResponse: {roundType: "normal"}, // To avoid double sending, leave empty if you are sending balanceUpdate elsewhere when a round starts. }); // console.log("roundStarted"); }; this.autoPlayStarted = function () { FEIM.send.autoPlayStarted(); } this.autoPlayStoped = function () { FEIM.send.autoPlayFinished(); } this.updateBet = function () { FEIM.send.betUpdate(integration.data.totalBet * 100); // console.log('betUpdate:', integration.data.totalBet * 100); } this.roundEnded = function () { FEIM.send.winUpdate({ win: integration.data.winAmount * 100 }); FEIM.send.roundFinished({ // playResponse: lastPlayResponse, // playResponse: {roundType: "normal"}, // finishedResponse: gamefinishedEndpointResponse }); // console.log("roundFinished", integration.data.winAmount); }; this.balance = function() { FEIM.send.balanceUpdate(integration.data.balance * 100); // console.log("balance", integration.data.balance * 100); }; this.showLoader = function() { FEIM.send.gameLoadStarted(); // console.log("gameLoadStarted"); }; this.hideLoader = function() { FEIM.send.gameLoadCompleted(); // console.log("gameLoadCompleted"); }; this.onAppFrameReady = function() { FEIM.send.updateSettings({sounds: document.querySelector(".input-for-sound").checked}); // console.log("updateSettings"); }; this.quit = function() { if (!FEIM.send.exitGame()) { /* There is a configuration problem, and game exit is not possible. This should not happen in production, and can be considered an error. */ console.error("exitGame error"); } else { // console.log("exitGame"); /* Nothing needs to be done; the operator will close the game frame, or FEIM will navigate to homeurl or go back in browser history. */ } }; this.receiveMessage = function() { let data = {}; let sendMessage = false; FEIM.on.freeze(()=>EventHandler("playInterrupted")) FEIM.on.unfreeze(()=>EventHandler("playResumed")) FEIM.on.pauseAutoPlay(()=>EventHandler("pauseAutoPlay")) FEIM.on.refreshBalance(() => EventHandler("refreshBalance")) FEIM.on.updateSettings((changedSettings) =>{ if (changedSettings.sounds !== undefined) { if (document.querySelector(".input-for-sound").checked != changedSettings.sounds) { integrationIframe.contentWindow.postMessage({name: "sound-toggle"}, "*"); document.querySelector(".input-for-sound").checked = changedSettings.sounds; document.querySelector(".input-for-background-music").checked = changedSettings.sounds; FEIM.send.updateSettings({ sounds: changedSettings.sounds }); } // $(".game-sound-bt").trigger( "click" ); } }) function EventHandler(event) { switch (event) { case "pauseAutoPlay": sendMessage = true; data.type = "integrationStopAutobet"; break; case "playInterrupted": sendMessage = true; data.type = "integrationStopAutobet"; integrationIframe.contentWindow.postMessage(data, "*"); data.type = "integrationDisableSpin"; break; case "playResumed": sendMessage = true; data.type = "integrationEnableSpin"; break; case "refreshBalance": // sendMessage = true; // data.type = "integrationRefreshBalance"; break; } if(sendMessage) integrationIframe.contentWindow.postMessage(data, "*"); } }; } function BetfairGameEvents() { this.gameDataLoaded = function() { }; this.roundStarted = function() { window.com.ppb.gc.sendGameAnimationStart(); }; this.autoPlayStarted = function () { } this.autoPlayStoped = function () { } this.updateBet = function () { // console.log('betUpdate:', integration.data.totalBet); window.com.ppb.gc.sendStakeUpdate(parseFloat(integration.data.totalBet), integration.data.currencyCode); } this.roundEnded = function () { // console.log("roundFinished", integration.data.winAmount); window.com.ppb.gc.sendGameAnimationCompleted(); window.com.ppb.gc.sendWinUpdate(parseFloat(integration.data.winAmount),integration.data.currencyCode); }; this.balance = function() { // console.log("balance", integration.data.balance); window.com.ppb.gc.sendBalanceUpdate({ realAmount: parseFloat(integration.data.balance), bonusAmount: 0 }, integration.data.currencyCode); }; this.showLoader = function() { // console.log("gameLoadStarted"); window.com.ppb.gc.sendGameLoadStarted(); }; this.hideLoader = function() { // console.log("gameLoadCompleted"); window.com.ppb.gc.sendGameLoadCompleted(); }; this.onAppFrameReady = function() { // console.log("updateSettings"); window.com.ppb.gc.sendSettingsUpdate("sound", document.querySelector(".input-for-sound").checked ? "on" : "off"); }; this.quit = function() { window.com.ppb.gc.sendEvent('exitGame'); }; this.errorMessage = function(notification) { if (notification) { if (Object.keys(notification).length > 3) { return; } if (Object.keys(notification).length === 1) { window.com.ppb.gc.sendErrorMessage(notification.Code); } if (Object.keys(notification).length === 2) { window.com.ppb.gc.sendErrorMessage(notification.Code, notification.Message); } if (Object.keys(notification).length === 3) { window.com.ppb.gc.sendErrorMessage(notification.Code, notification.Message, notification.errorParameters); } return; }; window.com.ppb.gc.sendErrorMessage(integration.errorMessage.Status ? integration.errorMessage.Status : false, integration.errorMessage.Message); }; this.receiveMessage = function() { let data = {}; let sendMessage = false; // FEIM.on.freeze(()=>EventHandler("playInterrupted")) // FEIM.on.unfreeze(()=>EventHandler("playResumed")) // FEIM.on.pauseAutoPlay(()=>EventHandler("pauseAutoPlay")) // FEIM.on.refreshBalance(() => EventHandler("refreshBalance")) // FEIM.on.updateSettings((changedSettings) =>{ // if (changedSettings.sounds !== undefined) { // if (document.querySelector(".input-for-sound").checked != changedSettings.sounds) { // integrationIframe.contentWindow.postMessage({name: "sound-toggle"}, "*"); // document.querySelector(".input-for-sound").checked = changedSettings.sounds; // document.querySelector(".input-for-background-music").checked = changedSettings.sounds; // FEIM.send.updateSettings({ sounds: changedSettings.sounds }); // } // // $(".game-sound-bt").trigger( "click" ); // } // }) window.addEventListener('message', EventHandler, false); function EventHandler(event) { if (event.data.payload && event.data.payload.settingName && event.data.payload.settingName == 'gameEventSound') { window.com.ppb.gc.sendSettingsUpdate("sound", event.data.payload.settingValue ? "on" : "off"); } if (event.data.payload && event.data.payload.settingName && event.data.payload.settingName == 'sound') { if (document.querySelector(".input-for-sound").checked != event.data.payload.settingValue) { // integrationIframe.contentWindow.postMessage({name: "sound-toggle"}, "*"); // document.querySelector(".input-for-sound").checked = event.data.payload.settingValue; // document.querySelector(".input-for-background-music").checked = event.data.payload.settingValue; // FEIM.send.updateSettings({ sounds: changedSettings.sounds }); $(".game-sound-bt").trigger("click"); } } if (sendMessage) integrationIframe.contentWindow.postMessage(data, "*"); } }; } $(document).ready(function () { integrationName = $('#HiddenCompanyName').val(); integrationIframe = document.querySelector('#game-frame'); //disable quit when no returnurl if (!getReturnurl()) { $('.menu-popup-exit-game').css('display', 'none'); $('.menu-popup-spinId').css('padding-left', '93px'); $('.menu-popup-spinId').css('border-bottom-left-radius', '15px'); $('.game-exit-bt').css('display', 'none'); $('.exit-game').css('display', 'none'); } //disable quit when no returnurl END if (integrationName.toLowerCase().includes('pariplay')) { PariPlayGameEvents.prototype = new GameEvents(); gameEvent = new PariPlayGameEvents(); } else if (integrationName === 'gan') { GanGameEvents.prototype = new GameEvents(); gameEvent = new GanGameEvents(); } else if (integrationName === 'solid') { SolidGameEvents.prototype = new GameEvents(); gameEvent = new SolidGameEvents(); } else if (integrationName === 'microgaming') { MicrogamingGameEvents.prototype = new GameEvents(); gameEvent = new MicrogamingGameEvents(); } else if (integrationName === 'relaxgaming') { RelaxGameEvents.prototype = new GameEvents(); gameEvent = new RelaxGameEvents(); } else if (integrationName.toLowerCase().includes('betfair')) { BetfairGameEvents.prototype = new GameEvents(); gameEvent = new BetfairGameEvents(); } if (gameEvent) { gameEvent.receiveMessage(); } });